<template>
    <el-dialog  :title="title" :visible.sync="dialogFormVisible" class="detail-dialog" ref="form">
        <el-form ref="form" :model="formData" label-width="100px" class="box_acct_form" :rules="rules">
            <el-form-item label="开始时间:" prop="startdate"  v-if="title=='车位通知管理'">
                <el-date-picker type="date" align="right" placeholder="请输入开始时间" v-model="formData.startdate"
                    style="width: 100%" class="width-full" clearable>
                </el-date-picker>
            </el-form-item>
            <el-form-item label="开始时间:" prop="startdate"  v-if="title=='车位通知详情'" >
                <el-date-picker type="date" align="right" placeholder="请输入开始时间" v-model="formData.startdate"
                    style="width: 100%" class="width-full" clearable disabled>
                </el-date-picker>
            </el-form-item>
         
            <el-form-item label="结束时间:" prop="enddate" v-if="title=='车位通知管理'">
                <el-date-picker type="date" align="right" placeholder="请输入结束时间" v-model="formData.enddate"
                    style="width: 100%" class="width-full" clearable>
                </el-date-picker>
            </el-form-item>
            <el-form-item label="结束时间:" prop="enddate" v-if="title=='车位通知详情'">
                <el-date-picker type="date" align="right" placeholder="请输入结束时间" v-model="formData.enddate"
                    style="width: 100%" class="width-full" clearable disabled>
                </el-date-picker>
            </el-form-item>

            <el-form-item label="应缴金额:" prop="orderpay" v-if="title=='车位通知管理'">
                <el-input size="medium" v-model="formData.orderpay" clearable></el-input>
            </el-form-item>
            <el-form-item label="应缴金额:" prop="orderpay" v-if="title=='车位通知详情'">
                <el-input size="medium" v-model="formData.orderpay" clearable disabled></el-input>
            </el-form-item>
            <el-form-item label="缴费状态:" prop="orderstatus" v-if="title=='车位通知管理'">
                <el-select v-model="formData.orderstatus" placeholder="缴费状态" clearable style="width: 15%; margin-left: 15px">
                    <el-option :value="1" label="已缴费" />
            <el-option :value="2" label="未缴费" />
                </el-select>
            </el-form-item>
            <el-form-item label="缴费状态:" prop="orderstatus" v-if="title=='车位通知详情'">
                <el-select v-model="formData.orderstatus" placeholder="缴费状态" clearable style="width: 15%; margin-left: 15px" disabled>
                    <el-option :value="1" label="已缴费" />
            <el-option :value="2" label="未缴费" />
                </el-select>
            </el-form-item>
            <el-form-item label="处理结果:"  v-if="title=='车位通知管理'">
                <el-input type="textarea" v-model="formData.note" clearable></el-input>
            </el-form-item>
            <el-form-item label="处理结果:"  v-if="title=='车位通知详情'" >
                <el-input type="textarea" v-model="formData.note" clearable disabled> </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" size="medium" style="float: right;text-align: center;width: 100px; margin-left: 10px;" @click="close()">关闭</el-button>
                <el-button type="primary" size="medium" style="float: right;text-align: center;width: 100px"
                    @click="handleSubmit" v-if="title=='车位通知管理'">通知</el-button>
                <el-button type="primary" size="medium" style="float: right;text-align: center;width: 100px"
                    @click="reset()"  v-if="title=='车位通知管理'">重置</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import moment from 'moment'

export default {
    name: "parkDialog",
    data() {
        return {
            title:'车位通知管理',
            dialogFormVisible: false,
            formData: {},
            type: '',
            rules:{
                startdate: [
          { required: true,  message: "日期不能为空", trigger: "blur" },
        ],
         enddate: [
          { required: true,  message: "日期不能为空", trigger: "blur" },
        ],
        orderpay: [
          { required: true, message: "应交金额不能为空", trigger: "blur" },
        ],
        orderstatus: [
          { required: true, message: "缴费状态不能空", trigger: "blur" },
        ],
            },
            statusList: [
                {
                    text: '已缴费',
                    value: '1'
                },
                {
                    text: '未缴费',
                    value: '2'
                },
            ],
        }
    },
    created() {
        this.$axiosToken({
            url: '/users/getUserByToken',
            method: 'get',
            data: {},
            success: (result => {
                this.type = result.type;
            })
        });
    },
    methods: {
        init(row) {
            this.formData = row;
        },
        handleSubmit() {
            this.$refs["form"].validate((valid) => {
        if (!valid) {
          this.$message.error({
            message: "必填项不能为空",
            duration: 2000,
          });
        } else {
            this.$axiosToken({
                url: '/parking/editParkOrder',
                method: 'post',
                data: {
                    u_id: this.formData.id,
                    startdate: this.dateFormat1(this.formData.startdate),
                    enddate: this.dateFormat1(this.formData.enddate),
                    orderpay: this.formData.orderpay,
                    orderstatus: this.formData.orderstatus,
                    note: this.formData.note
                },
                success: (result) => {
                    this.$parent.getSmartData();
                    this.$message({
                        showClose: true,
                        message: '通知成功',
                        type: 'success'
                    });
                }
            });
            this.dialogFormVisible = false
        }
      });
        },
        reset() {
            this.formData = {
                startdate: '',
                enddate: '',
                orderpay: '',
                orderstatus: '',
                note: ''
            }
        },
        dateFormat1(date) {
            if (date == undefined) {
                return ''
            } else {
                return moment(date).format("YYYY-MM-DD+HH:mm:ss")
            }
        },
        close() {
            this.dialogFormVisible = false
            this.$parent.getSmartData()
        }
    }
}
</script>

<style scoped>
/deep/.el-dialog__title {
    font-size: 24px;
    line-height: 24px;
    font-weight: bold;
    color: #303133;
}

/deep/.el-textarea__inner {
    font-family: 微软雅黑;
    font-size: 14px;
}
</style>